﻿Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports NHibernate
Imports NHibernate.Transaction
Imports SIAVU.Dominio

Namespace Persistencia

    Public Class BatchPersistencia

        Public Function getByMesEjecucion(ByVal mesEjecucion As Integer) As Batch
            Dim session As ISession = Nothing
            Dim oListBatch As List(Of Batch)

            Try
                session = NHibernateHelper.OpenSession
                oListBatch = session.CreateCriteria(GetType(Batch)).Add(Criterion.Expression.Eq("MesEjecucion", mesEjecucion)).List(Of Batch)()

                If (oListBatch.Count > 0) Then
                    Return oListBatch(0)
                Else
                    Return Nothing
                End If

            Catch ex As Exception
                Throw

            Finally
                session.Close()
            End Try
        End Function

        Public Sub guardar(ByVal oBatch As Batch)
            Dim session As ISession = NHibernateHelper.OpenSession()
            Dim oTransaccion As ITransaction = Nothing
            Try
                oTransaccion = session.BeginTransaction()
                oTransaccion.Begin()

                session.SaveOrUpdate(oBatch)
                oTransaccion.Commit()

            Catch ex As Exception
                oTransaccion.Rollback()
                Throw

            Finally
                session.Close()
            End Try
        End Sub

    End Class

End Namespace

